
/*队列模块功能测试*/

#include "../mqserver/mq_queue.hpp"
#include <gtest/gtest.h>


const std::string defaultfile = "./db/data.db";
xgmq::MsqQueueManagger::ptr mqmp;

// 编写全局测试套件
class QueueTest : public testing::Environment
{
public:
    void SetUp() override
    {
        // 初始化环境
        mqmp = std::make_shared<xgmq::MsqQueueManagger>(defaultfile);
    }
    void TearDown() override
    {
        // 清理环境
        mqmp->clear();
    }
};

// 新增队列的测试
TEST(queue_test, insert_test)
{
    std::unordered_map<std::string, std::string> mp = {{"k1", "v1"}, {"k2", "v2"}};
    mqmp->declareQueue("队列1",true,true,false,mp);
    mqmp->declareQueue("队列2",true,true,false,mp);
    mqmp->declareQueue("队列3",true,true,false,mp);
    mqmp->declareQueue("队列4",true,true,false,mp);
    mqmp->declareQueue("队列5",true,true,false,mp);

    ASSERT_EQ(mqmp->size(),5);
}

// 删除队列测试
TEST(queue_test, delete_test)
{
    mqmp->deleteQueue("队列1");
    mqmp->deleteQueue("队列2");
    mqmp->deleteQueue("队列3");

    ASSERT_EQ(mqmp->size(),2);
}

// 获取队列测试
TEST(queue_test, get_test)
{
    xgmq::MsgQueue::ptr exp = mqmp->getQueue("队列5");
    ASSERT_NE(exp.get(),nullptr);//为空就不继续往下走了
    ASSERT_EQ(exp->name,std::string("队列5"));
    ASSERT_EQ(exp->durable,true);
    ASSERT_EQ(exp->exclusive,true);
    ASSERT_EQ(exp->auto_delete,false);
    ASSERT_EQ(exp->getArgs(),std::string("k2=v2&k1=v1&"));
}


int main(int argc, char *argv[])
{
    testing::InitGoogleTest(&argc, argv);
    // 添加全局测试套件
    testing::AddGlobalTestEnvironment(new QueueTest);
    int ret = RUN_ALL_TESTS();

    return 0;
}